﻿using System.Linq;
using Microsoft.SharePoint.Navigation;

namespace System.Modules.SharePoint.Extensions
{
    /// <summary>
    /// SP Navigation Extensions
    /// </summary>
    public static class SPNavigationExtensions
    {
        #region Get Node by Title
        /// <summary>
        /// This method gets node by Title
        /// </summary>
        /// <param name="navigation">SPNavigation</param>
        /// <param name="title">string</param>
        /// <param name="comparison"></param>
        /// <returns></returns>
        public static SPNavigationNode GetNodeByTitle(this SPNavigation navigation, string title, StringComparison comparison)
        {
            return navigation.QuickLaunch.Cast<SPNavigationNode>().FirstOrDefault(node => node.Title.Equals(title, comparison));
        }
        #endregion
    }
}